/*
 * @Author: nns4
 * @Date: 2021-02-02 15:55:59
 * @LastEditors: nns4
 * @FilePath: /studyNote/note/js/常用效果/index.js
 * @Description: 
 */


// 判断当前元素在当前视图是否能够被看见
const elementIsVisibleInViewport = el => {
    const {
        top,
        left,
        bottom,
        right
    } = el.getBoundingClientRect();
    const {
        innerHeight,
        innerWidth
    } = window;
    return top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
};




function lyy() {
    return promise = new Promise((resolve, reject) => {
        setTimeout(() => {
            if (true) {
                resolve('我叫刘莹莹')
            } else {
                reject("我不是刘莹莹")
            }
  
        }, 2000)
    })
  }
  function lyy2(){
    return promise = new Promise((resolve, reject) => {
      setTimeout(() => {
          if (true) {
              resolve('我叫刘莹莹2')
          } else {
              reject("我不是刘莹莹2")
          }
  
      }, 1000)
  })
  }
  async function getlyy() {
    Promise.race([lyy(),lyy2()]).then(res => { 
        console.log(res)
    }).catch(res => { 
        console.log(res)
    })
  }
  getlyy()


// lyy().then(res => {
//     console.log(res)
// }).catch(res => {
//     console.log(res)
// }).finally(() => { 
//     console.log("成不成功都执行")
// })